package com.king.util.page;

/**
 * 分页核心
 * @author WDY
 * @date 2016-4-27 下午2:05:03
 */
public class PageCore {
	private int currentPage=1;//默认第一页
	private int pageSize=6;//每页行数
	private int begin;
	private int end;
	
	/**总行数**/
	private int rows;
	/**计算的总页数**/
	private int totalPage;
	public int getRows() {
		return rows;
	}
	
	public void setRows(int rows) {
		this.rows = rows;
	}

	/**
	 * 根据总行数计算总页数
	 * @return
	 */
	public int getTotalPage() {
		if (rows % pageSize == 0) {
			totalPage = rows / pageSize;
		} else {
			totalPage = rows / pageSize + 1;
		}
		return totalPage;
	}
	/**
	 * 
	 * @param totalPage
	 */
	public void setTotalPage(int totalPage){
		this.totalPage=totalPage;
	}
	/**
	 * 在Mybatis中使用时计算
	 * @return
	 */
	public int getBegin(){
		begin=(currentPage-1)*pageSize;
		return begin;
	}
	public void setBegin(int begin){
		this.begin=begin;
	}
	/**
	 * 在Mybatis中使用时计算
	 * @return
	 */
	public int getEnd(){
		end=currentPage*pageSize+1;
		return end;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize>100?6:pageSize;
	}
	public void setEnd(int end) {
		this.end = end;
	}
	public String toString() {
		return "Page [currentPage=" + currentPage + ", pageSize=" + pageSize
				+ ", begin=" + begin + ", end=" + end + ", rows=" + rows
				+ ", totalPage=" + totalPage + "]";
	}
}
